package otherTest;


import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.Connection.Response;
import org.junit.Test;
import org.slf4j.MDC;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpSession;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class otherTest01 {


    @Test
    public void test1() {
//        short s = 1;
//        s = s + 1;
//        System.out.println(s);
        int[] arr1 = {100, 200, 300};

        System.out.println(arr1);
        System.out.println(arr1[0]);
        System.out.println(arr1[1]);
        System.out.println(arr1[2]);

        int[] arr2 = arr1;

        arr2[0] = 111;
        arr2[1] = 222;
        arr2[2] = 333;

        System.out.println("---------");
        System.out.println(arr1);
        System.out.println(arr1[0]);
        System.out.println(arr1[1]);
        System.out.println(arr1[2]);

        System.out.println(arr2);
        System.out.println(arr2[0]);
        System.out.println(arr2[1]);
        System.out.println(arr2[2]);

    }


    private static String mvPutMonthCodes = "01M,02N,03O,04P,05Q,06R,07S,08T,09U,10V,11W,12X";
    private static String mvCallMonthCodes = "01A,02B,03C,04D,05E,06F,07G,08H,09I,10J,11K,12L";

    @Test
    public void test2() {
        // 股票期权  strikePrice
        String seriesID = "HKB46.00J4W04";
        seriesID = seriesID.substring(3);
        System.out.println(seriesID);
        Matcher lvMatcher = Pattern.compile("\\d+.\\d+").matcher(seriesID);
        if (lvMatcher.find()) {
            String lvResult = lvMatcher.group(0);
            System.out.println(lvResult);
        }
    }

    public static String getPutCall(String month, String seriesID) {
        String lvResult = "";
        try {
            String[] lvYearAndMonth = month.split("-");
            String lvMonth = lvYearAndMonth.length == 2 ? lvYearAndMonth[1] : month.substring(month.length() - 2);
            String lvCode = String.valueOf(seriesID.charAt(seriesID.length() - 2));
            String lvMonthCode = lvMonth.concat(lvCode);
            if (mvPutMonthCodes.indexOf(lvMonthCode) > -1) {
                lvResult = "P";
            } else if (mvCallMonthCodes.indexOf(lvMonthCode) > -1) {
                lvResult = "C";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lvResult;
    }

    public static String getContractMonth(String seriesID) {
        String lvResult = "";
        try {
            char lvYear = seriesID.charAt(seriesID.length() - 1);
            char lvMouth = seriesID.charAt(seriesID.length() - 2);
            int lvCurrentYear = Calendar.getInstance().get(Calendar.YEAR);
            lvCurrentYear /= 10;
            lvCurrentYear = lvCurrentYear * 10 + Integer.parseInt(String.valueOf(lvYear));
            lvResult += lvCurrentYear + "-";
            String lvMouthCodes = mvPutMonthCodes + mvCallMonthCodes;
            int lvMouthIndex = lvMouthCodes.indexOf(lvMouth);
            lvMouthCodes = lvMouthCodes.substring(lvMouthIndex - 2, lvMouthIndex);
            lvResult += lvMouthCodes;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lvResult;
    }

    @Test
    public void test3() {
        // 股票期权  callput
        String seriesID = "HKB46.00J4W04";
        System.out.println(getPutCall("2023-12", seriesID));
    }

    @Test
    public void test4() {
        // 股票期权  contractMonth
        String seriesID = "HKB46.00J4W04";
        System.out.println(getContractMonth(seriesID));
    }

    @Test
    public void test5() {
        // chatAt indexOf
        String seriesID = "HKB46.00J4W04";
        System.out.println(seriesID.charAt(3));
        System.out.println(seriesID.indexOf('4'));
    }

    @Test
    public void test6() {
        // chatAt indexOf
        BigDecimal bb = new BigDecimal(0.2333).pow(20);
        BigDecimal aa = null;
  /*      System.out.println(String.valueOf(aa));
        System.out.println(String.valueOf(bb));
        System.out.println(bb.toPlainString());
        System.out.println(aa.toPlainString());*/


        System.out.println(String.valueOf(bb));
        System.out.println(bb.toPlainString());
    }


    public static class AA {
        private BigDecimal aa;

        public BigDecimal getAa() {
            return aa;
        }

        public void setAa(BigDecimal aa) {
            this.aa = aa;
        }
    }

    @Test
    public void test7() {
        AA aa = new AA();
        System.out.println(aa.aa);
        System.out.println(aa.aa == null);
        String result = String.valueOf(aa.aa);
        System.out.println(result); // 输出 "null"
    }


    @Test
    public void test8() {
        String lvValidate = "true";
        List<String> lvXXSScriptFilterList = splitToVector("',\",=,script,alert,jndi,ldap,rmi,or,and,union", ",");
        for (int i = 0; i < lvXXSScriptFilterList.size(); i++) {
            String lvFilter = lvXXSScriptFilterList.get(i);
            if (!"confirmItem".equalsIgnoreCase("columns") && ("confirmItem".toLowerCase().indexOf(lvFilter.toLowerCase()) > -1 || "on".toLowerCase().indexOf(lvFilter.toLowerCase()) > -1)) {
                lvValidate = "false";
            }
        }
        System.out.println(lvValidate);
    }


    @Test
    public void test9() {
        System.out.println(!"confirmItem".equalsIgnoreCase("columns") && ("confirmItem".toLowerCase().indexOf("rmi".toLowerCase()) > -1 || "on".toLowerCase().indexOf("rmi".toLowerCase()) > -1));
    }

    public static Vector<String> splitToVector(String pType, String pDelim) {
        Vector<String> lvResult = new Vector<String>();
        try {
            if (null != pDelim) {

                StringTokenizer lvTokenizer = new StringTokenizer(pType, pDelim);

                while (lvTokenizer.hasMoreTokens()) {
                    lvResult.add(lvTokenizer.nextToken());
                }
            } else if (null != pType) {
                lvResult.add(pType);
            }
        } catch (Exception ex) {

        }
        return lvResult;
    }

    @Test
    public void test10() {
        String lvRegexSql = "\\b(or|and|union)\\b";
        String lvParamKeyStr = "this dasdworsa daandwa";
        String lvParamValueStr = "sdawds";
        Pattern lvPatternRegexSql = Pattern.compile(lvRegexSql, Pattern.CASE_INSENSITIVE);
        if (lvPatternRegexSql.matcher(lvParamKeyStr).find() || lvPatternRegexSql.matcher(lvParamValueStr).find()) {
            System.out.println("false");
        }
    }

    @Test
    public void test11() {
        String lvRegexSql = "\\b(or|and|union)\\b";
        String lvParamKeyStr = "this dasdworsa daandwa";
        String lvParamValueStr = "sdawds";
        Pattern lvPatternRegexSql = Pattern.compile(lvRegexSql, Pattern.CASE_INSENSITIVE);
        if (lvPatternRegexSql.matcher(lvParamKeyStr).find() || lvPatternRegexSql.matcher(lvParamValueStr).find()) {
            System.out.println("false");
        }
    }

    @Test
    public void test12() {
        String lvConnectURL = "https://localhost:28091/api" + ("/api/services/auth/user/login".substring("/api/services/auth/user/login".indexOf("/api") + 4));
        System.out.println(lvConnectURL);

        System.out.println("===================================");
        System.out.println("/api/services/auth/user/login".indexOf("/api"));
        System.out.println("/api/services/auth/user/login".indexOf("/api") + 4);
        System.out.println("/api/services/auth/user/login".substring(4));

    }

    @Test
    public void test14() {
        String lvConnectURL = "https://localhost:28091/api" + ("/api/services/auth/user/login".substring("/api/services/auth/user/login".indexOf("/api") + 4));
        System.out.println(lvConnectURL);

        System.out.println("===================================");
        System.out.println("/api/services/auth/user/login".indexOf("/api"));
        System.out.println("/api/services/auth/user/login".indexOf("/api") + 4);
        System.out.println("/api/services/auth/user/login".substring(4));

    }

    @Test
    public void test15() {
        try {
            String lvConnectUrl = "http://localhost:28092/api/services/auth/user/login";
            String lvMethod = "POST";
            Map<String,String> lvHeaders = new HashMap<>();
            Map<String, String> lvParameters = new HashMap<String, String>();
            lvParameters.put("language","en_US");
            String lvRequestBody = new String ("{\"loginID\":\"bea005\",\"passwd\": \"*****\",\"deviceName\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36\",\"loginIP\":\"\",\"captcha\":\"3\",\"language\":\"en_US\",\"deviceID\":\"58ff80-2d5bb1-10a728-fc5f94\",\"channelID\":\"INT\"}");
            Connection lvConnection = Jsoup.connect(lvConnectUrl);
            lvConnection.method(Connection.Method.valueOf(lvMethod))
                    .headers(lvHeaders)
                    .validateTLSCertificates(false)
                    .ignoreContentType(true)
                    .ignoreHttpErrors(true)
                    .data(lvParameters);
            // POST method to set request body
            if (lvMethod.equals("POST")) {
                lvConnection.requestBody(lvRequestBody);
            }
            Response lvResponse = null;

            lvResponse = lvConnection.execute();

            // Check response status
            if (lvResponse.statusCode() == 200) {
                if (lvResponse.contentType() != null && lvResponse.contentType().indexOf("application/json") > -1) {
                    System.out.println(lvResponse.body());
                } else {
                    System.out.println(Arrays.toString(lvResponse.bodyAsBytes()));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void test16() {
        String regex = "\\b(script|alert|jndi|ldap|rmi|focus|load|document|location|undefined|or|and|union)\\b";
        String lvValue = "fsgsdfg=fresfer";
        Pattern lvPatternRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        if (lvPatternRegex.matcher(lvValue).find()) {
            System.out.println("匹配到了");
        }
    }

    @Test
    public void test17() {
        SafeSimpleDateFormat  mvDateFormatter = new SafeSimpleDateFormat("yyyy-MM-dd");
        Date date= new Date(1697385600000L);
        System.out.println(mvDateFormatter.format(date));

        Date date2= new Date(1697126400000L);
        System.out.println(mvDateFormatter.format(date2));

    }

    @Test
    public void test18() {
        String aa = "Aa";
        String bb = "BB";
        System.out.println(aa.hashCode());
        System.out.println(bb.hashCode());
        HashSet<String> set = new HashSet<>();
        set.add(aa);
        set.add(bb);
        System.out.println(set);
        System.out.println("=========================");
        otherTest.AA.BB bb1  = new otherTest.AA.BB();
        otherTest.AA.BB bb2  = new otherTest.AA.BB();
        System.out.println(bb1.hashCode());
        System.out.println(bb2.hashCode());
        HashSet<otherTest.AA.BB> set2 = new HashSet<>();
        set2.add(bb1);
        set2.add(bb2);
        System.out.println(set2);
    }


    @Test
    public void test19() {
        TreeSet<String> set = new TreeSet<>();
        set.add("e");
        set.add("b");
        set.add("d");
        set.add("a");

        System.out.println(set);

        System.out.println("=================");
        char v1[] = {'a'};
        char v2[] = {'b'};
        System.out.println(v1[0]-v2[0]);
    }

    @Test
    public void test20() {
        System.out.println(1<<4);
    }

    @Test
    public void test21() {
        System.out.println("test merge333");
    }
}
